package com.coship.vas.dapg.service.impl;

import java.rmi.RemoteException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.coship.vas.dapg.dao.AssociationDAO;
import com.coship.vas.dapg.dao.common.Page;
import com.coship.vas.dapg.entity.AssociatedMsg;
import com.coship.vas.dapg.service.DynamicAssociationService;
import com.coship.vas.dapg.util.AgentAdapterUtil;
import com.coship.vas.dapg.util.ConfigUtil;
import com.coship.vasadapter.service.TopResultObj;
import com.coship.vasadapter.service.TopVasAsset;

/**
 * 
 * @作者 905613 陈开源 深圳市同洲电子股份有限公司(增值运营产品线)
 * 
 */
@Service("dynamicAssociationService")
@Transactional
public class DynamicAssociationServiceImpl implements DynamicAssociationService 
{
	
	@Autowired
	private AssociationDAO associationDAO;
	
	/**
	 * 取得点播排行
	 * @param limits
	 * @param startRow
	 * @return
	 */
	@Override
	public TopVasAsset[] getVODRank(int limits,int startRow)
	{
		try {
			TopResultObj result = AgentAdapterUtil.getDefaultInstance().getVodRank(limits, startRow);
			TopVasAsset[] resultList = result.getAssetList();
			return resultList;
		} catch (RemoteException e) {
			e.printStackTrace();
		}	
		return null;
	}
	
	/**
	 * 跳转点播节目详情页
	 * @param userid
	 * @return
	 */
	@Override
	public String getForwardHref(String userid)
	{
		String forward_url = ConfigUtil.getConfig("FORWARD_URL");
		return forward_url.replaceAll("<userId>", "userId="+userid);
	}

	/**
	 * 获取关联消息
	 * @return
	 */
	@Override
	public AssociatedMsg getAssociatedMsg(String version, String triggerType,String channelId, String smcId) 
	{
		String hql = "select am.* from AssociatedMsg am where am.channelId = '"+channelId+"'";
		Page<AssociatedMsg> page = new Page<AssociatedMsg>();
		associationDAO.queryPage(page, hql);
		
		List<AssociatedMsg> rs = page.getResultList();
		if(rs != null && rs.size() > 0)
			return rs.get(0);
		
		return null;
	}

	/**
	 * 获取消息配置信息
	 * @param version
	 * @return
	 */
	@Override
	public AssociatedMsg getMsgConfiguration(String version) 
	{
		return null;
	}
	
}
